﻿import * as cluster from 'cluster';
import * as os from 'os';
import child_process = require('child_process');

const size = os.cpus().length;

if (cluster.isMaster) {
    console.log('[master] ' + "start master...");

    for (var i = 0; i < size; i++) {
        cluster.fork();
    }

    cluster.on('exit', function () {
        console.log('A worker process died, restarting...');
        cluster.fork();
    });

    cluster.on('listening', function (worker, address) {
        console.log('[master] ' + 'listening: worker' + worker.id + ',pid:' + worker.process.pid + ', Address:' + address.address + ":" + address.port);
    });

} else if (cluster.isWorker) {
    require("./http");
}

